package com.cr.web.controller.api;

import com.cr.business.domain.TbUserEntityInfo;
import com.cr.business.service.ITbUserEntityInfoService;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 用户认证相关接口 控制类
 */
@RestController
@RequestMapping("api/auth")
public class UserAuthenticationController extends BaseController {

    @Resource
    private ITbUserEntityInfoService tbUserEntityInfoService;

    /**
     * 新增用户主体认证信息
     * @param tbUserEntityInfo 认证信息
     */
    @PostMapping("add")
    public AjaxResult add(@Valid TbUserEntityInfo tbUserEntityInfo){
        return toAjax(tbUserEntityInfoService.insertTbUserEntityInfo(tbUserEntityInfo));
    }

    /**
     * 修改用户主体认证信息
     * @param tbUserEntityInfo 认证信息
     */
    @PutMapping("update/{entityId}")
    public AjaxResult update(@PathVariable("entityId") String entityId, @Valid TbUserEntityInfo tbUserEntityInfo){
        tbUserEntityInfo.setEntityId(entityId);
        return toAjax(tbUserEntityInfoService.updateTbUserEntityInfo(tbUserEntityInfo));
    }

    /**
     * 获取用户主体认证信息
     */
    @GetMapping("get")
    public AjaxResult getUserEntityInfo(){
        return AjaxResult.success(tbUserEntityInfoService.selectTbUserEntityInfo());
    }
}
